package com.zuxia.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.zuxia.entity.Title;
import com.zuxia.service.ITitleService;


@Controller("titleAction")
@Scope("prototype")//定义单例或多例
@ParentPackage("json-default")
@Namespace("/")
@Results({
	@Result(name="success",type="dispatcher",location="/admin/Journalism.jsp"),
	@Result(name="yes",type="redirectAction",location="/selectTitle"),
	@Result(name="no",type="redirectAction",location="/selectTitle"),
	@Result(name="display",type="dispatcher",location="/news_IndustryNews.jsp"),
	@Result(name="display1",type="dispatcher",location="/news_upkeep.jsp"),
	@Result(name="displays",type="dispatcher",location="/news_IndustryNews2.jsp"),
	@Result(name="displayZ",type="dispatcher",location="/news.jsp"),
	@Result(name="json",type="json")
})
public class TitleAction extends ActionSupport implements ModelDriven<Title>{

	private static final long serialVersionUID = 1L;
	
	private Title title =new Title();
	
	private List<Title> titles;
	private int titlesSize;

	@Resource(name="titleService")
	private ITitleService titleService;
	
	public Title getModel() {
		return title;
	}
	
	@Action("addTitle")
	public String addTitle(){
		
		return titleService.svaeTitle(title);
	}
	@Action("selectTitle")
	public String selectTitle(){
		titles =titleService.findAll();
		titlesSize=titles.size();
		ActionContext.getContext().put("titles", titles);
		
		return "success";
	}

	@Action("selectTitleZ")
	public String selectTitlez(){
		titles =titleService.findAll();
		ActionContext.getContext().put("titlesZ", titles);
		
		return "displayZ";
	}

	@Action("selectTitles1")
	public String selectTitle1(){
		titles =titleService.selectTitle2("汽车");
		ActionContext.getContext().put("titles1", titles);		
		return "display";
	}

	@Action("selectTitless2")
	public String selectTitle2(){
		titles =titleService.selectTitle2("汽车保养");
		ActionContext.getContext().put("titles1", titles);		
		return "display1";
	}
	
	@Action("selectTitlesD")
	public String selectTitlesD(){
		titles =titleService.selectTitle2("汽车保养");
		ActionContext.getContext().getValueStack().push(titles);	
		return "json";
	}
	
	@Action("selectTitles")
	public String selectTitles(){
		titles =titleService.selectTitle1(title);
		ActionContext.getContext().put("titless", titles);
		
		return "displays";
	}
	@Action("updateTitle")
	public String updateTitle() {
		return titleService.updateTitle(title);
	}
	@Action("deleteTitle")
	public String deleteTitle(){
		return titleService.deleteTitle(title);
	}

	public List<Title> getTitles() {
		return titles;
	}

	public void setTitles(List<Title> titles) {
		this.titles = titles;
	}

	public int getTitlesSize() {
		return titlesSize;
	}

	public void setTitlesSize(int titlesSize) {
		this.titlesSize = titlesSize;
	}
	
	
	
}
